package com.woniuxy.sd.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.struts2.ServletActionContext;

public class FileAction {
	
	private File upload;
	private String uploadContentType;
	private String uploadFileName;
	
	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	
	public String execute() {
		System.out.println(upload.getName());
		System.out.println(uploadFileName);
		System.out.println(uploadContentType);
		
		String path = ServletActionContext.getServletContext().getRealPath("/file");
		
		try {
			FileInputStream fis = new FileInputStream(upload);
			byte[] context = new byte[fis.available()];
			fis.read(context);
			fis.close();
			
			FileOutputStream fos = new FileOutputStream(path+"/"+uploadFileName);
			fos.write(context);
			fos.flush();
			fos.close();
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return "fl";
	}
}

